// url为完整的url地址:baseUrl + url
//仅支持预览图片，offic三件套
//该url必须经过URL编码，并且该url必须可以在Internet上公开访问




//***************未完工***************//
export default (url) => {
	//获取文件格式
	let format = url.split('.').pop()
	//判断文件格式
	if (format == 'jpg' || format == 'jpeg' || format == 'bmp' || format == 'png' || format == 'tif' ||
		format == 'gif' || format == 'pcx' || format == 'tga' || format == 'exif' || format == 'fpx' ||
		format == 'svg' || format == 'psd' || format == 'cdr' || format == 'pcd' || format == 'dxf' ||
		format == 'ufo' || format == 'eps' || format == 'ai' || format == 'raw' || format == 'WMF' ||
		format == 'webp') {
		openFile('image',url)
	}else if(format == 'pdf'){
		openFile('pdf',url)
	} else if (format == 'doc' || format == 'docx' || format == 'xlsx' || format == 'xls' || format == 'csv' ||
		format ==
		'pptx' || format == 'pptm' || format == 'ppt' || format == 'potx' || format == 'potm' || format ==
		'pot') {
		openFile('office',url)
	} else {
		uni.showToast({
			title: '文件暂不支持预览',
			icon: 'none'
		})
	}
}
function openFile(type,url){
	//判断PC端还是APP端
	//PC端
	if (window.navigator.userAgent.includes('Windows')) {
		//判断文件类型
		if(type === 'image'){
			window.open('/pages/index?img=' + url)
		}else if(type === 'pdf'){
			window.open('/pages/index?pdf=' + url)
		}else{
			console.log(url);
			// window.open('https://view.officeapps.live.com/op/view.aspx?src=' + url)
		}
	//APP端
	} else {
		if(type === 'image'){
			let imgList = []
			imgList.push(url) //因为previewImage的urls只能为数组，所以创建一个
			uni.previewImage({
				urls:imgList,
			})
		}else if(type === 'pdf'){
			uni.navigateTo({
				url:'/pages/index?pdf=' + url
			})
		}else{
			plus.runtime.openWeb('https://view.officeapps.live.com/op/view.aspx?src=' + url)
		}
	}
}
